package com.leyou.page.web;

import com.leyou.page.service.PageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

import java.util.Map;

/**
 * @author 虎哥
 */
@Controller
public class PageController {

    @Autowired
    private PageService pageService;

    @GetMapping("/item/{id}.html")
    public String toItemHtml(@PathVariable("id") Long spuId, Model model){
        // 1.根据spuId查询商品的信息
        Map<String,Object> itemData = pageService.loadItemData(spuId);
        // 2.把这些信息放入Model
        model.addAllAttributes(itemData);

        return "item";
    }
}
